﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RimWorld;
using Verse;

namespace ARMIR
{
    public class ThingComp_writeMemory : ThingComp {
        public CompProperties_writeMemory Props => (CompProperties_writeMemory)props;
        // 私有支持字段
        private List<string> familyNumbers;
        private Faction theFaction;
        private int recordTimes;

        // 公共属性
        public List<string> FamilyNumbers
        {
            get
            {
                if (familyNumbers == null)
                    familyNumbers = new List<string>();
                return familyNumbers;
            }
            set => familyNumbers = value;
        }

        public Faction theFacton
        {
            get => theFaction;
            set => theFaction = value;
        }

        public int recourdTimes
        {
            get => recordTimes;
            set => recordTimes = value;
        }

        public override void PostPostMake()
        {
            base.PostPostMake();
            // 确保列表被初始化
            familyNumbers = new List<string>();
            theFaction = null;
            recordTimes = 0;
        }

        public override void PostExposeData()
        {
            base.PostExposeData();

            // 使用支持字段进行保存加载
            Scribe_Collections.Look(ref familyNumbers, "familyNumbers", LookMode.Value);
            Scribe_References.Look(ref theFaction, "theFaction");
            Scribe_Values.Look(ref recordTimes, "recordTimes", 0);

            // 加载时的兼容性检查
            if (Scribe.mode == LoadSaveMode.LoadingVars && familyNumbers == null)
            {
                familyNumbers = new List<string>();
            }
        }
    }
}
